home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 09 - 1993 / 09.09 Sep 93 / Programmer's Challenge / test.c next >
Encoding:
C/C++ Source or Header  |  1993-07-11  |  2.8 KB  |  113 lines  |  [TEXT/KAHL]

  1. /*****************************************************
  2.  * test.c
  3.  *
  4.  * Driver function and example TileStackWindows
  5.  * function to test out TileStackWindows.
  6.  ****************************************************/
  7.  
  8. #include "TileStackWindows.h"
  9.  
  10. /*****************************************************
  11.  * defines
  12.  ****************************************************/
  13.  
  14. #define NUM_TEST_WINDOWS        20
  15.  
  16. /*****************************************************
  17.  * prototypes
  18.  ****************************************************/
  19.  
  20. static Boolean StackWindows(Rect *enclosingRectPtr,
  21.     WindowElementPtr p, int wCount);
  22.  
  23. /*****************************************************
  24.  * main
  25.  ****************************************************/
  26. void main()
  27. {
  28.     WindowPtr    *p, windowPtrArray[NUM_TEST_WINDOWS];
  29.     Rect        theBounds;
  30.     int            i;
  31.     
  32.     theBounds.top = 50;
  33.     theBounds.left = 50;
  34.     theBounds.bottom = 200;
  35.     theBounds.right = 200;
  36.     
  37.     p = windowPtrArray;
  38.     i = NUM_TEST_WINDOWS;
  39.     do {
  40.         *p++ = NewWindow(0L, &theBounds, "\pTest",
  41.             TRUE, 0, (WindowPtr) -1, TRUE, 0);
  42.         OffsetRect(&theBounds, 3, 2);
  43.     } while (--i);
  44.         
  45.     TileStackWindows(StackWindows);
  46. }
  47.  
  48.  
  49. /* window stacking variables used by StackWindows */
  50. #define WTitleHeight    18
  51. #define StaggerH        7
  52. #define StaggerV        (WTitleHeight - 2)
  53. #define MinVertSize        200
  54. #define NextRowOffsetH    2
  55. #define NextRowOffsetV    4
  56.  
  57. /*****************************************************
  58.  * StackWindows -- example TileStackWindows proc
  59.  *
  60.  * Stack all the windows so you can see their
  61.  * titles. Returns TRUE if we moved or sized at
  62.  * least one window (if not then we don't need to
  63.  * redraw the screen).
  64.  ****************************************************/
  65. static Boolean StackWindows(enclosingRectPtr, p, wCount)
  66. Rect                *enclosingRectPtr;
  67. WindowElementPtr    p;
  68. int                    wCount;
  69. {
  70.     WindowPtr            w;
  71.     Rect                theBounds;
  72.     Point                upperLeft;
  73.     int                    width;
  74.     Boolean                didOne, sizeChanged;
  75.     
  76.     theBounds = *enclosingRectPtr;
  77.     theBounds.top += WTitleHeight;
  78.     upperLeft = topLeft(theBounds);
  79.     width = theBounds.right - theBounds.left;
  80.     
  81.     didOne = FALSE;
  82.     
  83.     /* this particular routine starts at the back
  84.      * of the list and works it's way forward
  85.      * (to the frontmost window)
  86.      */
  87.     p += wCount;
  88.     do {
  89.         p--;
  90.         w = (WindowPtr) p->theWindowPtr;
  91.         sizeChanged = MySizeWindow(w,
  92.             theBounds.right - theBounds.left,
  93.             theBounds.bottom - theBounds.top);
  94.         didOne |= sizeChanged;
  95.         didOne |= MyMoveWindow(w, theBounds.left,
  96.             theBounds.top, sizeChanged);
  97.         theBounds.left += StaggerH;
  98.         theBounds.right += StaggerH;
  99.         theBounds.top += StaggerV;
  100.         if (theBounds.top >
  101.           enclosingRectPtr->bottom - MinVertSize) {
  102.             upperLeft.h += NextRowOffsetH;
  103.             upperLeft.v += NextRowOffsetV;
  104.             topLeft(theBounds) = upperLeft;
  105.             theBounds.right = theBounds.left + width;
  106.         }
  107.         if (theBounds.right > enclosingRectPtr->right)
  108.             theBounds.right = enclosingRectPtr->right;
  109.     } while (--wCount);
  110.     
  111.     return (didOne);
  112. }
  113.